package com.ggs.rg.ybjb.systemmodule.handler;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * ClassName:CommonInterceptor
 * Package:com.ggs.rg.ybjb.usermodule.handler
 * Description:
 *
 * @Date:2021/10/23 19:54
 * @Author:记录后端处理请求的总耗时
 */

public class CommonInterceptor implements HandlerInterceptor {

    private Long start;
    private Long end;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //记录程序开始时间，用于记录处理业务所需时间
        start = System.currentTimeMillis();
        System.out.println("经过通用拦截器,所有请求都必须经过这里!!!");
        //放行
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        end = System.currentTimeMillis();
        System.out.println("系统总共耗时:"+(end-start));
    }

}
